import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

class User{
    public String name;
    public String password;
}
@WebServlet("/postJson")

public class PostJson extends HttpServlet {
    //建立一个Json的核心对象
    private ObjectMapper objectMapper=new ObjectMapper();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    User user=objectMapper.readValue(req.getInputStream(),User.class);
    resp.getWriter().write("name:"+user.name+" password "+user.password);
    }
}
